<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Load tỉnh thành quận huyện phường xã</title>
<script src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
	

	function getDistrict(IDProvince)
	{
		if (IDProvince=="")
		  {
		  document.getElementById("getDistrict").innerHTML="";
		  return;
		  } 
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("getDistrict").innerHTML=xmlhttp.responseText;
			}
		  }
		xmlhttp.open("GET","getDistrict.php?IDProvince="+IDProvince,true);
		xmlhttp.send();	
	}	
	function getWard(IDDistrict)
	{
		if (IDDistrict=="")
		  {
		  document.getElementById("getWard").innerHTML="";
		  return;
		  } 
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("getWard").innerHTML=xmlhttp.responseText;
			}
		  }
		xmlhttp.open("GET","getWard.php?IDDistrict="+IDDistrict,true);
		xmlhttp.send();	
	}	
</script>
</head>

<body>
	<form action="" method="get" name="Location" id="Location">
    	<table>
        	<tr>
            	<td><label><?php echo "Tỉnh/Thành phố"; ?></label></td>
  				<td>
                	 <?php
						include "config.php";
						$sql = "select * from province"; 
						$result = mysql_query($sql, $conn);				
						echo "<select name='IDProvince' onchange='getDistrict(this.value)' id='IDProvince'>";
						echo "<option>Select Province</option>";
						
						while($row = mysql_fetch_row($result))
						{
							echo "<option value='$row[0]'>".$row[1]."</option>";
						}
						echo "</select>";
					?>
                </td>
                <tr>
                	<td colspan="2"><div id="getDistrict"></div></td>
           		</tr>
             	<tr>
                	<td colspan="2"><div id="getWard"></div></td>
            	</tr>
            </tr>
        </table>
    </form>
</body>
</html>